﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using SmartHYU_TestVersion.Life;

namespace SmartHYU_TestVersion.Life
{
    public partial class Bob : PhoneApplicationPage
    {
        HYUbob bob = new HYUbob();
        List<BobDate> bobDates = new List<BobDate>();

        public Bob()
        {
            InitializeComponent();

            // Prograss bar
            downloadingProgressBar.IsIndeterminate = true;

            // Display Local Data First
            dateListBox.ItemsSource = bob.GetDateListToBobDate();

            // Download Bob
            bob.DownloadMenuAsync("modaWP7", "Seoul");
            bob.downloadBobCompleted += new HYUbob.DownloadBobComplete(bob_downloadBobCompleted);
        }

        void bob_downloadBobCompleted(bool completedStatus, string bobMenu)
        {
            // Parse and Display
            bob.ParseXmlFromIsolatedStorage();
            
            bobDates = bob.GetDateListToBobDate();

            dateListBox.ItemsSource = bobDates;

            // hide prograss bar
            downloadingProgressBar.IsIndeterminate = false;
            downloadingProgressBar.Visibility = System.Windows.Visibility.Collapsed;

        }

        private void dateListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int idx;
            string bobDetailUri;

            idx = dateListBox.SelectedIndex;
            bobDetailUri = "/Life/HYUbobDetail.xaml?day=" +
                bobDates.Skip(idx).First().DateByInteger;

            NavigationService.Navigate(new Uri(bobDetailUri, UriKind.Relative));
        }
    }
}